package com.sxh.permission.controller;

import com.sxh.permission.result.Result;
import com.sxh.permission.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class PermissionController {
    @Autowired
    private PermissionService permissionService;
    //绑定默认角色
    @GetMapping("/permission/{id}")
    public Result bindDefaultRole(@PathVariable("id") Long id) {
        permissionService.bindDefaultRole(id);
        return Result.success();
    }

    //查询用户的角色码
    @GetMapping("/permission/getUserRoleCode/{id}")
    public String getUserRoleCode(@PathVariable("id") Long id) {
        return permissionService.getUserRoleCode(id);
    }
    //根据权限查询用户id
    @GetMapping("/permission/queryUserIdByRoleId/{roleCode}")
    public List<Long> queryUserIdByRoleId(@PathVariable("roleCode")String rodeCode) {
        return permissionService.queryUserIdByRoleCode(rodeCode);
    }
//    //查询所有用户id
//    @GetMapping("/permission/queryAllUserId")
//    public List<Long> queryAllUserId() {
//        return permissionService.queryAllUserId();
//    }
    // 超管调用：升级用户为管理员
    @GetMapping("/permission/upgradeToAdmin/{userId}")
    public void upgradeToAdmin(@PathVariable("userId") Long userId) {
        permissionService.upgradeToAdmin(userId);
    }
    // 超管调用：降级用户为普通角色
    @GetMapping("/permission/downgradeToUser/{userId}")
    public void downgradeToUser(@PathVariable("userId")Long userId) {
        permissionService.downgradeToUser(userId);
    }
}
